/*
 * TowerEntitie.cpp
 *
 *  Created on: Jan 19, 2013
 *      Author: raysue
 */

#include "game/entities/TowerEntitie.h"
#include "util/Helpers.h"
#include "game/entities/EatsStage.h"
#include <vector>

using namespace eats_core;
using namespace eats_helpers;
using namespace std;

int TowersIndex::CATODIX_PRICE = 50;
int TowersIndex::CATODIX_TILE_SIZE = 45;
int TowersIndex::CATODIX_DEMAGE = 1;

int TowersIndex::SUFURIX_PRICE = 110;
int TowersIndex::SUFURIX_TILE_SIZE = 45;
int TowersIndex::SUFURIX_DEMAGE = 2;


TowerEntitie::TowerEntitie(SDL_Surface * surface, int posX, int posY) : GameObject(surface, posX, posY){
	_oldTime = SDL_GetTicks();
	_isActive = false;
}

TowerEntitie::~TowerEntitie() {
	// TODO Auto-generated destructor stub
}

bool TowerEntitie::loadAndEnableAnimation()
{
	std::cout << "|WARNING| Metodo não implementado. Evite usar esse metodo. Implementa na classe filha!" <<std::endl;
	return false;
}

bool TowerEntitie::setUp()
{
	return loadAndEnableAnimation() && GameObject::setUp() ;
}

bool TowerEntitie::update()
{
	if( ! _isActive )
	{
		return true;
	}

	//Perigoso isso aqui
	if ( _oldTime + _velocity > SDL_GetTicks() ){
		return true;
	}

	_oldTime = SDL_GetTicks();
	//EatsStage * temp = GameConteiner::getInstance()->getGameManager()-> _current_state;
	EatsStage * temp  = dynamic_cast<EatsStage*>(GameConteiner::getInstance()->getGameManager()-> _current_state);
	vector<BaseEnemy *> enemies = temp-> getEnemies();

	for(int i = 0; i < enemies.size(); i++ ) {
		if ( CoordinatesHelper::isOnRange( enemies.at(i)->getPoint() , position, _range) && enemies.at(i)->_isAlive) {
			cout<< (BaseEnemy*) enemies.at(i)->_heath << endl;
			attack( (BaseEnemy*) enemies.at(i));
		}

	}

	return GameObject::update();
}

bool TowerEntitie::tearDown()
{
	return GameObject::tearDown();
}

void TowerEntitie::attack(BaseEnemy * enemie)
{
	EatsStage * temp  = dynamic_cast<EatsStage*>(GameConteiner::getInstance()->getGameManager()-> _current_state);
	temp->goldMeter += enemie->sufferAttack(_damage);
}
